class monsterDialog extends renderer.DisplayObjectContainer{

    private titleText: renderer.TextField;
    private contentText: renderer.TextField;
    private rolexue: renderer.TextField;
    private defeat: renderer.TextField;
    private victory:  renderer.TextField;
    private mission: Mission;
    private clickIndex = 0;
    private mon:monster;
    private background:renderer.Bitmap;
    private CloseTexture:renderer.Bitmap;
    private dialogBackgroundTexture = new Image();
    private closeTexture = new Image();
    private roletexture=new Image();

    private guan:renderer.Bitmap;

    private shanghai: number;
 
    private c=new Image();
    private Roletexture:renderer.Bitmap;
    private NpcHeadTexture:renderer.Bitmap;
    private Guaiwu:renderer.Bitmap;

    private skillt1:renderer.Bitmap;
    private skillt2:renderer.Bitmap;
    private skillt3:renderer.Bitmap;
    private skillt0:renderer.Bitmap;


    private skillc1:renderer.TextField;
    private skillc2:renderer.TextField;
    private skillc3:renderer.TextField;


    private Escape: renderer.Bitmap;
    private escape=new Image();

    private Shibai:renderer.Bitmap;
    private Shengli:renderer.Bitmap;
    private shibai=new Image();
    private shengli=new Image();



    private backGroundContainer:renderer.DisplayObjectContainer;
    private ItemContainer:renderer.DisplayObjectContainer;
    constructor(mon:monster) {
        super();
        this.backGroundContainer=new renderer.DisplayObjectContainer();
        this.ItemContainer=new renderer.DisplayObjectContainer();

        this.dialogBackgroundTexture.src = 'battle.png';

        //this.closeTexture.src = 'icon.jpg';
     
        this.c.src="02.png";
        this.escape.src="qq.png";
        this.roletexture=user.roleTexturea;
       this. shibai.src="loser.png";
        this.shengli.src="vi.png";

        this.mon=mon;


        this.background = new renderer.Bitmap(100, 60, this.dialogBackgroundTexture);
        this.background.x=100;
        this.background.y=100;
       // this.background.scaleX = this.background.scaleY=0.9 ;

       // this.CloseTexture= new renderer.Bitmap(600, 100,this.closeTexture);
        //this.CloseTexture.scaleX = 0.7;
       // this.CloseTexture.scaleY =0.7;
        this.Roletexture=new renderer.Bitmap(100,200,this.roletexture);
        this.Roletexture.scaleX=this.Roletexture.scaleY=1;


        this.Escape=new renderer.Bitmap(400,100,this.escape);
        this.Escape.scaleX=this.Escape.scaleY;
     

       this.titleText= new renderer.TextField();
       this.titleText.text = this.mon.name;
       this.titleText.x = 500;
       this.titleText.y = 400;
       this.scaleX = this.scaleY = 1;

       this.contentText=new renderer.TextField();
       this.contentText.text=this.mon.attack.toString();
       this.contentText.x = 200;
       this.contentText.y = 400;


       this.rolexue=new renderer.TextField();
       this.rolexue.text=user.attack.toString();
       this.rolexue.x=500;
       this.rolexue.y=450;


       //this.guan=new renderer.Bitmap(100,100,this.escape);


       this.defeat=new renderer.TextField();
       this.victory=new renderer.TextField();
       this.defeat.text="失败!"
       this.victory.text="胜利!";
       this.victory.x=500;
       this.victory.y=400;
       this.defeat.x=500;
       this.defeat.y=450;
       this.skillc2=new renderer.TextField();
       this.skillc3=new renderer.TextField();
   




       // this.skillt1=new renderer.Bitmap(100,300,this.c);
        this.skillt2=new renderer.Bitmap(100,400,this.c);
        this.skillt3=new renderer.Bitmap(200,400,this.c);
        this.skillt0=new renderer.Bitmap(300,400,this.c);
        this.Shengli=new renderer.Bitmap(200,200,this.shengli);
        this.Shibai=new renderer.Bitmap(200,200,this.shibai);

        
       // this. NpcHeadTexture = new renderer.Bitmap(200, 200, user.roleTexturea);//zhujue
        this.Guaiwu=new renderer.Bitmap(400,200,this.mon.monsterImage);
        this.Guaiwu.scaleX=this.Guaiwu.scaleY=2.5;

     


        

        this.addChild(this.backGroundContainer);
        this.addChild(this.ItemContainer);
        this.backGroundContainer.addChild(this.background);
        //this.backGroundContainer.addChild(this.NpcHeadTexture);
     //   this.backGroundContainer.addChild(this.CloseTexture);
        this.backGroundContainer.addChild(this.Roletexture);
        this.backGroundContainer.addChild(this.Guaiwu);
        this.ItemContainer.addChild(this.titleText);
        this.ItemContainer.addChild(this.contentText);
        this.ItemContainer.addChild(this.rolexue);
        //this.ItemContainer.addChild(this.skillt1);
        this.ItemContainer.addChild(this.skillt2);
        this.ItemContainer.addChild(this.skillt3);
        this.ItemContainer.addChild(this.skillt0);
       // this.ItemContainer.addChild(this.Shengli);

        this.ItemContainer.addChild(this.Escape);
       // this.ItemContainer.addChild(this.guan);

        //guanbi
       this.Escape.addEventListener("click",()=>{
            this.mon.attack=100;
            user.attack=100;
            console.log(1111111);
            this.dispatchEvent("closebattle",{});
            openNode=" ";
          

        })
      

//逃跑
       /* this.CloseTexture.addEventListener("click",()=>{
           const id:any[] = ["map","map2","map3"];
            for (let i=0;i<id.length;i++){
                const b=mapManager.maps[id[i]];
                if(b.id==mon.mapID){
                    const map=b;
                    b.removeMonster(this.mon);

                }

            }

           /* this.mon.attack=100;
            user.attack=100;
            console.log(1111111);
             nopenNode=" ";*/

            //this.dispatchEvent("closebattle",{});
//  })


        //技能释放
        //一技能
       /* this.skillt1.addEventListener("click", ()=>{
        this.skillt1.dispatchEvent("battle",{});


        })
        let index=1;
        let v=1;
        this.skillt1.addEventListener("battle",() =>{
            index=index+1;
            
            const t1=new renderer.TextField();
            user.attack=user.attack+10;

            this.mon.hp-=10;
            for(let a of mountedItems){
                if(a){
                    if(a.id==this.mon.id){
                        //user.attack=user.attack+5;//药增加攻击5
                        this.mon.hp=this.mon.hp*0.94;//针对怪物嗜血6%
                        user.attack=user.attack-this.mon.attack*0.8;//药箱抵消攻击20%
                       // user.attack=user.attack+10;//刀攻击增加10
                        this.mon.hp=this.mon.hp-this.mon.hp*0.1;//刀暴击对怪物减少血量10%





                    }
                }


            }
            this.contentText.text=this.mon.hp.toString();
       
            t1.text="主角使用了1技能对"+this.mon.name+"造成了"+user.attack+"伤害";
            t1.y=index*10;
           
            this.ItemContainer.addChild(t1);
            index++;

            const intervalCount = setInterval(() => {

              /*  t1.text="主角使用了123对"+this.mon.name+"造成了"+"10伤害";
                t1.x=50+t1.x;
                t1.y=50+t1.y;   *        
               // user.hp -= 5;
                this.rolexue.text=user.attack.toString();


                const t2=new renderer.TextField();

           
                t2.text="怪物使用了对"+user.name+"造成了"+this.mon.attack+"伤害";
                t2.x=200;
                t2.y=index*10;
                this.ItemContainer.addChild(t2);




                clearInterval(intervalCount);

            }, 1000);
             
    if(this.mon.hp==0){
        this.ItemContainer.addChild(this.victory);
        this.victory.addEventListener("click",()=>{
            const id:any[] = ["map","map2","map3"];
            for (let i=0;i<id.length;i++){
                const b=mapManager.maps[id[i]];
                if(b.id==mon.mapID){
                    const map=b;
                    b.removeMonster(this.mon);
                    
                    b.drawItem(itemManager,this.mon);
                    
                    

                }
            }
                this.dispatchEvent("closebattle",{});
                
        })
    }
              
      /*  this.ItemContainer.removeChild(this.titleText);
        this.ItemContainer.removeChild(this.contentText);                  
        this.ItemContainer.addChild(this.victory);     
        this.backGroundContainer.removeChild(this.Guaiwu);                   
        })*/
        let index=1;

    
           this.skillt0.addEventListener("click", ()=>{
            this.skillt0.dispatchEvent("battle",{});
            })
            this.skillt0.addEventListener("battle",() =>{
                user.attack=user.attack+5;
    
                index=index+1;
                const t1=new renderer.TextField();
                this.contentText.text=this.mon.hp.toString();
                t1.text="主角使用了123对"+this.mon.name+"造成了"+user.attack+"伤害";
                t1.y=index*10;
                this.ItemContainer.addChild(t1);
                index++;
                t1.y=index*10;
                this.mon.hp-=20;
                for(let a of mountedItems){
                    if(a){
                        if(a.id==this.mon.id){
                            //user.attack=user.attack+5;//药增加攻击5
                            this.mon.hp=this.mon.hp*0.94;//针对怪物嗜血6%
                            user.attack=user.attack-this.mon.attack*0.8;//药箱抵消攻击20%
                           // user.attack=user.attack+10;//刀攻击增加10
                            this.mon.hp=this.mon.hp-this.mon.hp*0.1;//刀暴击对怪物减少血量10%
                        }
                    }
                }
                this.contentText.text=user.hp.toString();
                const intervalCount = setInterval(() => {
                     user.hp =user.hp-this.mon.attack*0.1;
                   // user.hp-= 5;
                    this.rolexue.text=user.hp.toString();
                    const t2=new renderer.TextField();   
                    index=index+1;      
                    t2.text="怪物使用了对"+user.name+"造成了"+this.mon.attack+"伤害";
                    t2.x=200;
                    t2.y=index*10;
                    this.ItemContainer.addChild(t2);
                    clearInterval(intervalCount);
    
                }, 1000);
                             
        if(this.mon.hp <0||this.mon.hp==0){
            this.ItemContainer.addChild(this.Shengli);
            this.Shengli.addEventListener("click",()=>{
                const id:any[] = ["map","map2","map3"];
                for (let i=0;i<id.length;i++){
                    const b=mapManager.maps[id[i]];
                    if(b.id==mon.mapID){
                        const map=b;
                        b.removeMonster(this.mon);
                        b.drawItem(itemManager,this.mon);
    
    
                        
    
                    }
                }
                    this.dispatchEvent("closebattle",{});
            })
        }
        if(user.hp<0||user.hp==0){
            this.ItemContainer.addChild(this.Shibai);
            this.Shibai.addEventListener("click",()=>{
                const id:any[] = ["map","map2","map3"];
                for (let i=0;i<id.length;i++){
                    const b=mapManager.maps[id[i]];
                    if(b.id==mon.mapID){
                        const map=b;
                        b.removeMonster(this.mon);
                        b.drawItem(itemManager,this.mon);
    
    
                        
    
                    }
                }
                    this.dispatchEvent("closebattle",{});
            })

        }
               
            })
    




       //二技能
       this.skillt2.addEventListener("click", ()=>{
        this.skillt2.dispatchEvent("battle",{});
        })
        this.skillt2.addEventListener("battle",() =>{
            user.attack=user.attack+5;

            index=index+1;
            const t1=new renderer.TextField();
            this.contentText.text=this.mon.hp.toString();
            t1.text="主角使用了123对"+this.mon.name+"造成了"+user.attack+"伤害";
            t1.y=index*10;
            this.ItemContainer.addChild(t1);
            index++;
            t1.y=index*10;
            this.mon.hp-=10;
            for(let a of mountedItems){
                if(a){
                    if(a.id==this.mon.id){
                        //user.attack=user.attack+5;//药增加攻击5
                        this.mon.hp=this.mon.hp*0.94;//针对怪物嗜血6%
                        user.attack=user.attack-this.mon.attack*0.8;//药箱抵消攻击20%
                       // user.attack=user.attack+10;//刀攻击增加10
                        this.mon.hp=this.mon.hp-this.mon.hp*0.1;//刀暴击对怪物减少血量10%
                    }
                }
            }
            this.contentText.text=this.mon.hp.toString();
            const intervalCount = setInterval(() => {
                user.hp =user.hp-this.mon.attack*0.3;
                index=index+1;      

                // user.hp-= 5;
               // user.hp-= 5;
                this.rolexue.text=user.hp.toString();
                const t2=new renderer.TextField();         
                t2.text="怪物使用了对"+user.name+"造成了"+this.mon.attack+"伤害";
                t2.x=200;
                t2.y=index*10;
                this.ItemContainer.addChild(t2);
                clearInterval(intervalCount);

            }, 1000);
                         
    if(this.mon.hp <0||this.mon.hp==0){
        this.ItemContainer.addChild(this.Shengli);
        this.Shengli.addEventListener("click",()=>{
            const id:any[] = ["map","map2","map3"];
            for (let i=0;i<id.length;i++){
                const b=mapManager.maps[id[i]];
                if(b.id==mon.mapID){
                    const map=b;
                    b.removeMonster(this.mon);
                    b.drawItem(itemManager,this.mon);


                    

                }
            }
                this.dispatchEvent("closebattle",{});
        })
    }
    if(user.hp<0||user.hp==0){
        this.ItemContainer.addChild(this.Shibai);
        this.Shibai.addEventListener("click",()=>{
            const id:any[] = ["map","map2","map3"];
            for (let i=0;i<id.length;i++){
                const b=mapManager.maps[id[i]];
                if(b.id==mon.mapID){
                    const map=b;
                    b.removeMonster(this.mon);
                    b.drawItem(itemManager,this.mon);


                    

                }
            }
                this.dispatchEvent("closebattle",{});
        })

    }
           
        })

       
      //三技能
       
        this.skillt3.addEventListener("click", ()=>{
        this.skillt3.dispatchEvent("battle",{});
        })
        this.skillt3.addEventListener("battle",() =>{
            user.attack=user.attack+2;

            index=index+1;

            index=index+0.5;
            const t1=new renderer.TextField();
            this.contentText.text=this.mon.hp.toString();
            t1.text="主角使用了123对"+this.mon.name+"造成了"+user.attack+"伤害";
            t1.y=index*10;
            this.ItemContainer.addChild(t1);
            index++;      
            this.mon.hp-=3;
            for(let a of mountedItems){
                if(a){
                    if(a.id==this.mon.id){
                        //user.attack=user.attack+5;//药增加攻击5
                        this.mon.hp=this.mon.hp*0.94;//针对怪物嗜血6%
                        user.attack=user.attack-this.mon.attack*0.8;//药箱抵消攻击20%
                       // user.attack=user.attack+10;//刀攻击增加10
                        this.mon.hp=this.mon.hp-this.mon.hp*0.1;//刀暴击对怪物减少血量10%





                    }
                }


            }
            this.contentText.text=this.mon.hp.toString();
            const intervalCount = setInterval(() => {
                index=index+1;      

                user.hp =user.hp-this.mon.attack*0.3;
                // user.hp-= 5;
               // user.hp -= 5;
                this.rolexue.text=user.hp.toString();
                const t2=new renderer.TextField();
                t2.text="怪物使用了对"+user.name+"造成了"+this.mon.attack+"伤害";
                t2.x=200;
                t2.y=index*10;
                this.ItemContainer.addChild(t2);
                clearInterval(intervalCount);

            }, 1000);  
                         
    if(this.mon.hp<0||this.mon.hp==0){
        this.ItemContainer.addChild(this.Shengli);
        this.Shengli.addEventListener("click",()=>{
            const id:any[] = ["map","map2","map3"];
            for (let i=0;i<id.length;i++){
                const b=mapManager.maps[id[i]];
                if(b.id==mon.mapID){
                    const map=b;
                    b.removeMonster(this.mon);
                    b.drawItem(itemManager,this.mon);


                    

                }
            }
                this.dispatchEvent("closebattle",{});
        })
    }   
    if(user.hp<0||user.hp==0){
        this.ItemContainer.addChild(this.Shibai);
        this.Shibai.addEventListener("click",()=>{
            const id:any[] = ["map","map2","map3"];
            for (let i=0;i<id.length;i++){
                const b=mapManager.maps[id[i]];
                if(b.id==mon.mapID){
                    const map=b;
                    b.removeMonster(this.mon);
                    b.drawItem(itemManager,this.mon);


                    

                }
            }
                this.dispatchEvent("closebattle",{});
        })

    }    
           
        })
   
    

}
}
    
        
   
    




